#include "help.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <thread>
#include <vector>
void helpMenu(){

    //打开文件
    std::ifstream file;
    file.open("help.txt", std::ios::in);
    if(!file.is_open()){
        std::cerr << "无法打开文件 help.txt" << std::endl;
        return;
    }

    // 使用 stringstream 读取整个文件内容
    std::stringstream buffer;
    buffer << file.rdbuf();

    // 输出help文件内容
    std::cout << buffer.str() << std::endl;

    // 关闭文件
    file.close();
}

int checkArgs(int argc,char *argv[],scanInfo &scanInfo){
    if(argc == 2 && (std::string(argv[1]) == "-h" || std::string(argv[1]) == "-help")) {
        helpMenu();
        return 1;
    }
    //检查参数个数
    if (argc < 5) {
        std::cerr << "Usage: " << argv[0] << " [-p | -n] [-c | -s | -a | -n | -f | -x | -sa] <hostname> <output_file> [port_range]" << std::endl;
        std::cerr << "Please enter -help for more information" << std::endl;
        return 0;
    }

    scanInfo.icmpScanMode = argv[1];
    scanInfo.portScanMode = argv[2];
    scanInfo.ip = argv[3];
    scanInfo.fileName = argv[4];

    if(argc >=6){
        scanInfo.portRange = argv[5];
    }

    if(argc == 7){
        scanInfo.threadCount =  std::stoi(argv[6]);
    }

    return 2;
}

void checkFlag(int &startPort, int &endPort,std::string portRange)
{

    // 判断是否包含分隔符 "-"
    std::istringstream iss(portRange);
    std::string token;

    if(std::getline(iss, token, '-')){
        startPort = std::stoi(token);
        std::getline(iss, token, '-');
        endPort = std::stoi(token);
    }else{
        startPort = std::stoi(portRange);
        endPort = startPort;

    }

}
